import { defineStore } from 'pinia'
import { requestAuthor, requestSearchAuthorByDynastyOrName, requestDeleteAuthorById, requestUpadateAuthorById, requestDynasty, requestAddAuthor } from './manage-author.api'

export default defineStore('manageAuthor', {
    state: () => {
        return {
        }
    },
    getters: {
    },
    actions: {
        // 获取全部作者信息
        getAuthor(data: object) {
            return new Promise((resolve, reject) => {
                requestAuthor(data).then(response => {
                    const res: any = response.data
                    if (res.code === 200) {
                        resolve(res.data)
                    }
                })
            })
        },

        // 查询作者信息
        getSearchAuthorByDynastyOrName(data: object) {
            return new Promise((resolve, reject) => {
                requestSearchAuthorByDynastyOrName(data).then(response => {
                    const res: any = response.data
                    if (res.code === 200) {
                        resolve(res.data)
                    }
                })
            })
        },

        // 根据uid删除作者信息
        getDeleteAuthorById(data: object) {
            return new Promise((resolve, reject) => {
                requestDeleteAuthorById(data).then(response => {
                    const res: any = response.data
                    if (res.code === 200) {
                        resolve(res.data)
                    }
                })
            })
        },

        // 根据uid更改作者信息
        getUpadateAuthorById(data: object) {
            return new Promise((resolve, reject) => {
                requestUpadateAuthorById(data).then(response => {
                    const res: any = response.data
                    if (res.code === 200) {
                        resolve(res.data)
                    }
                })
            })
        },

        // 获取朝代信息
        getDynasty() {
            return new Promise((resolve, reject) => {
                requestDynasty().then(response => {
                    const res: any = response.data
                    if (res.code === 200) {
                        resolve(res.data)
                    }
                })
            })
        },

        // 添加作者信息
        getAddAuthor(data: object) {
            return new Promise((resolve, reject) => {
                requestAddAuthor(data).then(response => {
                    const res: any = response.data
                    if (res.code === 200) {
                        resolve(res.data)
                    }
                })
            })
        },
    }
})
